package com.fanqwz.hexieshe.adapter;

import android.databinding.DataBindingUtil;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.fanqwz.hexieshe.BR;
import com.fanqwz.hexieshe.R;
import com.fanqwz.hexieshe.databinding.CategoryListItemBinding;
import com.fanqwz.hexieshe.model.CategoryModel;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
 * Created by fanqw on 2017/7/2.
 */

public class CategoryAdapter extends BaseAdapter {
    private List<CategoryModel> categorys = new ArrayList<>(0);

    @Inject
    public CategoryAdapter() {
    }

    public void setCategorys(List<CategoryModel> categorys) {
        this.categorys = categorys;
    }

    @Override
    public int getCount() {
        return categorys.size();
    }

    @Override
    public Object getItem(int position) {
        return categorys.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            CategoryListItemBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.category_list_item, parent, false);
            convertView = binding.getRoot();
            convertView.setTag(binding);
        }

        CategoryListItemBinding binding = (CategoryListItemBinding) convertView.getTag();
        binding.setVariable(BR.category, getItem(position));
        return convertView;
    }
}
